﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CServiceStack.WebHost.Endpoints;
using SomeServices;
using CServiceStack.Validation;
using CServiceStack.Plugins.ProtoBuf;
using CServiceStack.Plugins.FastInfoset;


namespace SomeServiceHost
{
    public class MockServiceHost : AppHostHttpListenerBase
    {
        public MockServiceHost()
            : base(typeof(TingService).Assembly)
        {
            //this.RequestFilters.Add((req, res, dto) =>
            //{
            //   //Type serviceType = EndpointHost.Metadata.GetServiceTypeByOpName(req.OperationName);
            //   //Console.WriteLine(serviceType);
            //    RequestCounter.DECR();
            //});
            //this.ResponseFilters.Add((req, res, dto) =>
            //    {
            //        RequestCounter.DECR();
            //    });
            TingService.Init();
        }

        public override void Configure(Funq.Container container)
        {
            //Plugins.RemoveAll(new Predicate<IPlugin>(plugin => true));
            Plugins.Add(new ValidationFeature());
            Plugins.Add(new SomeFormat());
            Plugins.Add(new SomeProtobufFormat());
            Plugins.Add(new ProtoBufFormat());
            Plugins.Add(new MMFProtobufFormat());
            Plugins.Add(new MMFFormat());
            Plugins.Add(new FastInfosetFormat());
            

            container.RegisterValidators(typeof(TingService).Assembly);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            MockServiceHost host = new MockServiceHost();
            host.Init();
            host.Start("http://localhost:2013/");
            Console.WriteLine("server started");
            Console.ReadKey();
        }
    }
}
